from typing import Optional, Tuple

from django.db.models import QuerySet

from server.apps.main.logic.posts import commands, queries, validation
from server.apps.main.models import Todo


def run(
    id: Optional[int],
    title: Optional[str],
    description: Optional[str],
    is_done: Optional[bool],
) -> Tuple[bool, bool, QuerySet[Todo]]:
    validated_data = validation.validate(
        title=title,
        description=description,
        is_done=is_done,
    )
    if validated_data:
        changed_task = commands.edit(id, validated_data)
    else:
        changed_task = 0
    return changed_task > 0, validated_data is not None, id

